def RRead():#用于输入RNA序列的函数，自带基础的检验功能
    RList = input("你好，请输入待翻译的RNA片段")
    RList = RList.upper()
    if len(RList) == 0:
        print("您似乎没有输入任何内容，请重试")
        return [0]
    if len(RList)%3 != 0:
        print("您输入的序列长度不是3的倍数，请重试")
        return [0]
    for i in RList:
        if i not in ["A", "U", "G", "C"]:
            print("您输入的序列中含有异常碱基，请重试")
            return [0]
    print("输入序列符合标准")
    return  [1, RList]

def 翻译():
    ADict = dict()#用于存放氨基酸密码信息的字典
    #丙氨酸
    ADict["GCU"] = ["A", "Ala", "丙氨酸"]
    ADict["GCC"] = ["A", "Ala", "丙氨酸"]
    ADict["GCA"] = ["A", "Ala", "丙氨酸"]
    #精氨酸
    ADict["CGU"] = ["R", "Arg", "精氨酸"]
    ADict["CGA"] = ["R", "Arg", "精氨酸"]
    ADict["CGC"] = ["R", "Arg", "精氨酸"]
    ADict["CGG"] = ["R", "Arg", "精氨酸"]
    ADict["AGA"] = ["R", "Arg", "精氨酸"]
    ADict["AGG"] = ["R", "Arg", "精氨酸"]
    #天冬酰胺
    ADict["AAU"] = ["N", "Asn", "天冬酰胺"]
    ADict["AAC"] = ["N", "Asn", "天冬酰胺"]
    #天冬氨酸
    ADict["GAU"] = ["D", "Asp", "天冬氨酸"]
    ADict["GAC"] = ["D", "Asp", "天冬氨酸"]
    #半胱氨酸
    ADict["UGU"] = ["C", "Cys", "半胱氨酸"]
    ADict["UGC"] = ["C", "Cys", "半胱氨酸"]
    #谷氨酰胺
    ADict["CAA"] = ["Q", "Gln", "谷氨酰胺"]
    ADict["CAG"] = ["Q", "Gln", "谷氨酰胺"]
    #谷氨酸
    ADict["GAA"] = ["E", "Glu", "谷氨酸"]
    ADict["GAG"] = ["E", "Glu", "谷氨酸"]
    #甘氨酸
    ADict["GGU"] = ["G", "Gly", "甘氨酸"]
    ADict["GGC"] = ["G", "Gly", "甘氨酸"]
    ADict["GGA"] = ["G", "Gly", "甘氨酸"]
    ADict["GGG"] = ["G", "Gly", "甘氨酸"]
    #组氨酸
    ADict["CAU"] = ["H", "His", "组氨酸"]
    ADict["CAC"] = ["H", "His", "组氨酸"]
    #异亮氨酸
    ADict["AUU"] = ["I", "Ile", "异亮氨酸"]
    ADict["AUC"] = ["I", "Ile", "异亮氨酸"]
    ADict["AUA"] = ["I", "Ile", "异亮氨酸"]
    #亮氨酸
    ADict["CUU"] = ["L", "Leu", "亮氨酸"]
    ADict["CUC"] = ["L", "Leu", "亮氨酸"]
    ADict["CUA"] = ["L", "Leu", "亮氨酸"]
    ADict["CUG"] = ["L", "Leu", "亮氨酸"]
    #赖氨酸
    ADict["AAA"] = ["K", "Lys", "赖氨酸"]
    ADict["AAG"] = ["K", "Lys", "赖氨酸"]
    #甲硫氨酸（蛋氨酸）
    ADict["AUG"] = ["M", "Met", "甲硫氨酸（蛋氨酸）"]
    #苯丙氨酸
    ADict["UUU"] = ["F", "Phe", "苯丙氨酸"]
    ADict["UUC"] = ["F", "Phe", "苯丙氨酸"]
    #脯氨酸
    ADict["CCU"] = ["P", "Pro", "脯氨酸"]
    ADict["CCC"] = ["P", "Pro", "脯氨酸"]
    ADict["CCA"] = ["P", "Pro", "脯氨酸"]
    ADict["CCG"] = ["P", "Pro", "脯氨酸"]
    #丝氨酸
    ADict["UCA"] = ["S", "Ser", "丝氨酸"]
    ADict["UCC"] = ["S", "Ser", "丝氨酸"]
    ADict["UCA"] = ["S", "Ser", "丝氨酸"]
    ADict["UCG"] = ["S", "Ser", "丝氨酸"]
    ADict["AGU"] = ["S", "Ser", "丝氨酸"]
    ADict["AGC"] = ["S", "Ser", "丝氨酸"]
    #苏氨酸
    ADict["ACU"] = ["T", "Thr", "苏氨酸"]
    ADict["ACC"] = ["T", "Thr", "苏氨酸"]
    ADict["ACA"] = ["T", "Thr", "苏氨酸"]
    ADict["ACG"] = ["T", "Thr", "苏氨酸"]
    #色氨酸
    ADict["UGG"] = ["W", "Trp", "色氨酸"]
    #酪氨酸
    ADict["UAU"] = ["Y", "Tyr", "酪氨酸"]
    ADict["UAC"] = ["Y", "Tyr", "酪氨酸"]
    #缬氨酸
    ADict["GUU"] = ["V", "Val", "缬氨酸"]
    ADict["GUC"] = ["V", "Val", "缬氨酸"]
    ADict["GUA"] = ["V", "Val", "缬氨酸"]
    ADict["GUG"] = ["V", "Val", "缬氨酸"]
    #硒代半胱氨酸
    ADict["UGA"] = ["U", "Sec", "硒代半胱氨酸"]
    #吡咯赖氨酸
    ADict["UAG"] = ["O", "Pyl", "吡咯赖氨酸"]
    
    SList = ["AUG", "GUG"]#起始密码子列表
    EList = ["UAA", "UAG", "UGA"]#终止密码子列表

    a = [0]
    AList = str()
    while a[0] != 1:
        a = RRead()
    #检查起始密码子并开始翻译
    if a[1][0: 3] not in SList:
        print("请注意，您输入的序列似乎不包括起始密码子")
    for i in range(len(a[1])):#攒够3个碱基，翻译一次
        if (i+1)%3 != 0:
            continue
        if i+1 < len(a[1]):
            if a[1][i-2: i+1] in ADict:
                AList = AList + ADict[a[1][i-2: i+1]][0]
            if a[1][i-2: i+1] not in ADict:
                AList = AList + "!"
                print("请注意，在序列中出现了终止密码子")
        else:
            if a[1][i-2: i+1] in EList:
                print("已完成翻译，结果为：{}".format(AList))
            else:
                AList = AList + ADict[a[1][i-2: i+1]][0]
                print("已完成翻译，结果为：{}".format(AList))
                print("请注意，结尾处不是终止密码子")
    return AList
